
<?
	if (!defined('i-Teck_ADMIN')) die("Hacking attempt");

	switch($mod){
		case "add":?>
     
<form id="form1" name="form1" method="post" action="">
		<article class="module width_full">
			<header><h3>Tin Nhanh</h3></header>
				<div class="module_content">
					<fieldset>
							<label>Nội dung Tin</label>
					</fieldset>
					<fieldset>
							<center><textarea name="noidung" cols="50" rows="10" id="noidung"></textarea>
							<script language="javascript1.2">generate_wysiwyg('noidung');</script></center>
					</fieldset>
					<fieldset>
							<label>Hiển thị</label>
					</fieldset>
					<fieldset>
							<center>
									<input type="radio" name="hienthi" value="0"  checked="checked"/>Không      
									<input type="radio" name="hienthi" value="1"/>Có
							</center>
					</fieldset>
						
					<input type="submit" name="cmd" id="cmd" value="Thêm" class="alt_btn">
				</div>
		</article><!-- end of styles article -->
</form>
<?
	if(isset($_POST["cmd"])=="Thêm"){
		mysql_query("INSERT INTO shop_tinnhanh (noidung,hienthi) values
					('".addslashes($_POST["noidung"])."',
					'".intval($_POST["hienthi"])."')");
	
		echo"<meta http-equiv='refresh' content='0; url=?act=tinnhanh&mod=view'>";
		}


	break; 
	case "view":?>
<?
	$result=mysql_query("SELECT * FROM shop_tinnhanh");
	if(mysql_num_rows($result)<=0){echo"<center>Chưa có dữ liệu</center>";}
?>
<form id="form2" name="form2" method="post" action="">
<article class="module width_full">
			<header><h3>Quản lý</h3></header>
	
		<div class="tab_container">
			<div id="tab1" class="tab_content">
			<table class="tablesorter" cellspacing="0"> 
			<thead> 
				<tr> 
    				<th>ID</th> 
    				<th>Nội dung</th> 
    				<th>Sửa</th> 
    				<th>Xóa</th>
				</tr> 
			</thead> 
			<tbody> 
    <? while($r=mysql_fetch_array($result)){?>
    <tr>
      <td><?=$r["id"];?></td>
      <td><?=$r["noidung"];?></a></td>
      
      </td>
      <td><a href=?act=tinnhanh&mod=edit&id=<? echo $r['id'];?>>Sửa</a></td>
    <td><a onClick="return  confirm('Bạn có muốn xóa sản phẩm này ko');"href=?act=tinnhanh&mod=delete&id=<? echo $r['id'];?>>Xóa</a></td>
    </tr>
    <? }?>
			</tbody> 
			</table></div></div>
		</article><!-- end of styles article -->
</form>
<? 

break;
case "edit":
$id=intval($_GET["id"]);
$re=mysql_query("SELECT * FROM shop_tinnhanh where id=$id");
while($r=mysql_fetch_array($re)){
?>

<form id="form1" name="form1" method="post" action="">
<article class="module width_full">
			<header><h3>Liên hệ</h3></header>
				<div class="module_content">
					<fieldset>
							<label>Sửa tin nhanh</label>
					</fieldset>
					<fieldset>
							<center><textarea name="noidung" cols="50" rows="10" id="noidung"><?=stripslashes($r['noidung']);?></textarea>
							<script language="javascript1.2">generate_wysiwyg('noidung');</script></center>
					</fieldset>
					<fieldset>
							<label>Hiển thị</label>
					</fieldset>
					<fieldset>
							<center>
									<input type="radio" name="hienthi" value="0" <? if($r['hienthi']=="0"){echo'checked="checked"';}?>/>Không
									<input type="radio" name="hienthi" value="1"<? if($r['hienthi']=="1"){echo'checked="checked"';}?>/>Có
							</center>
					</fieldset>
						
					<input type="submit" name="cmd" id="cmd" value="Sửa" class="alt_btn">
				</div>
		</article><!-- end of styles article -->
</form>
<?
}
	if(isset($_POST["cmd"])=="Sửa"){
			mysql_query("UPDATE shop_tinnhanh SET noidung='".addslashes($_POST["noidung"])."',
											 hienthi='".intval($_POST["hienthi"])."' WHERE id=$id");
			mysql_close();
			echo"<meta http-equiv='refresh' content='0; url=?act=tinnhanh&mod=view'>";
		}

break;
case "delete":
		$id=intval($_GET["id"]);
		mysql_query("delete from shop_tinnhanh where id=$id");
		mysql_close();
		echo "<meta http-equiv='refresh' content='0; url=?act=tinnhanh&mod=view'>";
break;

	} 
?>
  
  
  
  
  
  
